<?php
class RequirementTypesController extends AppController {

	var $name = 'RequirementTypes';
	var $helpers = array('Html','Form','Ajax','Javascript');
	
	var $paginate = array(
	'limit' => 2
	);
	
	var $components = array('RequestHandler');
	

	function index() {
		$this->RequirementType->recursive = 0;
		$this->set('requirementTypes', $this->paginate());
	}

	function view($id = null) {
		if (!$id) {
			$this->Session->setFlash(__('Invalid RequirementType.', true));
			$this->redirect(array('action'=>'index'));
		}
		$this->set('requirementType', $this->RequirementType->read(null, $id));
	}

	function add() {
		if (!empty($this->data)) {
			$this->RequirementType->create();
			if ($this->RequirementType->save($this->data)) {
				$this->Session->setFlash(__('The RequirementType has been saved', true));
				$this->redirect(array('action'=>'index'));
			} else {
				$this->Session->setFlash(__('The RequirementType could not be saved. Please, try again.', true));
			}
		}
	}

	function edit($id = null) {
		if (!$id && empty($this->data)) {
			$this->Session->setFlash(__('Invalid RequirementType', true));
			$this->redirect(array('action'=>'index'));
		}
		if (!empty($this->data)) {
			if ($this->RequirementType->save($this->data)) {
				$this->Session->setFlash(__('The RequirementType has been saved', true));
				$this->redirect(array('action'=>'index'));
			} else {
				$this->Session->setFlash(__('The RequirementType could not be saved. Please, try again.', true));
			}
		}
		if (empty($this->data)) {
			$this->data = $this->RequirementType->read(null, $id);
		}
	}

	function delete($id = null) {
		if (!$id) {
			$this->Session->setFlash(__('Invalid id for RequirementType', true));
			$this->redirect(array('action'=>'index'));
		}
		if ($this->RequirementType->del($id)) {
			$this->Session->setFlash(__('RequirementType deleted', true));
			$this->redirect(array('action'=>'index'));
		}
	}
	
	function list_requirement_types() {
		$this->RequirementType->recursive = 0;
		$this->set('requirementTypes', $this->paginate());
	}

	function new_requirement_type() {
		
		$this->layout = 'ajax';

		if (!empty($this->data)) {
			$this->RequirementType->create();
			if ($this->RequirementType->save($this->data)) {
				$this->Session->setFlash(__('The Requirement Type has been saved', true));

				$this->redirect(array('controller'=>'pages','action'=>'blank'));
			} else {
				$this->Session->setFlash(__('The RequirementType could not be saved. Please, try again.', true));
			}
		}
	}

}
?>